﻿using System.Windows;
using System.Windows.Controls;

namespace AmiCheckin.UI.Views
{
    public partial class GlobalView : UserControl
    {
        public GlobalView()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            this.ViewModel.Save();
            MessageBox.Show("保存成功~请手动重载config.json");
        }

        private void UserControl_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
            this.ViewModel.Load();
        }

        private void Button_AddMaster(object sender, System.Windows.RoutedEventArgs e)
        {
            if (InputDialog.GetInput(out var input))
            {
                ViewModel.Masters.Add(long.Parse(input));
            }
           
        }

        private void Button_DelMaster(object sender, System.Windows.RoutedEventArgs e)
        {
            if (MastersList.SelectedIndex != -1)
                ViewModel.Masters.RemoveAt(MastersList.SelectedIndex);
        }

        private void Button_AddGroup(object sender, System.Windows.RoutedEventArgs e)
        {
            if (InputDialog.GetInput(out var input))
            {
                ViewModel.EnableGroups.Add(long.Parse(input));
            }
        }

        private void Button_DelGroup(object sender, System.Windows.RoutedEventArgs e)
        {
            if (EnableGroupsList.SelectedIndex != -1)
                ViewModel.EnableGroups.RemoveAt(EnableGroupsList.SelectedIndex);
        }

        private void Button_ReloadConfig(object sender, RoutedEventArgs e)
        {
            AmiCheckin.Code.AmiCheckin.LoadConfig();
            MessageBox.Show("重载完成~");

        }
    }
}